﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Display;

namespace hzGis.service.impl
{
   public class LayerOutService
    {
       /// <summary>
       /// 设置布局地图的大小
       /// </summary>
       /// <param name="axPageLayoutControl">布局控件</param>
       /// <param name="outMinx">外边框minx</param>
        /// <param name="outMiny">外边框miny</param>
        /// <param name="outMaxx">外边框maxx</param>
        /// <param name="outMaxy">外边框maxy</param>
        /// <param name="mapMinx">内边框minx</param>
        /// <param name="mapMiny">内边框miny</param>
        /// <param name="mapMaxx">内边框maxx</param>
        /// <param name="mapMaxy">内边框maxy</param>
       /// <param name="pageWidth">页面宽度</param>
       /// <param name="pageHeight">页面高度</param>
       /// <param name="direction">方向</param>
       public void setLayerOutHorizontal( AxPageLayoutControl axPageLayoutControl, double outMinx, double outMiny, double outMaxx, double outMaxy,
           double mapMinx, double mapMiny, double mapMaxx, double mapMaxy, double pageWidth, double pageHeight, short direction)
       {
           IGraphicsContainer pGraphicsContainer = (IGraphicsContainer)axPageLayoutControl.PageLayout;
           // 设置默认边框
           ISymbolBorder pSymborder = new SymbolBorder() as ISymbolBorder;
           pSymborder.CornerRounding = 0;
           IBorder pBorder = pSymborder;
           // 设置外框
           IEnvelope pEnvelop_out = new Envelope() as IEnvelope;
           // 设置外框的大小
           pEnvelop_out.PutCoords(outMinx, outMiny, outMaxx, outMaxy);
           // 添加外框
           IFrameElement fe = new FrameElement() as IFrameElement;
           fe.Border = pBorder;
           IElement pe = (IElement)fe;
           pe.Geometry = pEnvelop_out as IGeometry;
           pGraphicsContainer.AddElement(pe, 0);
           // 设置地图的大小
           IMapFrame pMapFrame = (IMapFrame)pGraphicsContainer.FindFrame(axPageLayoutControl.ActiveView.FocusMap);
           pMapFrame.Border = pBorder;
           pMapFrame.ExtentType = esriExtentTypeEnum.esriAutoExtentBounds;
           IElement pElement = (IElement)pMapFrame;
           IEnvelope pEnvelop = new Envelope() as IEnvelope;
           pEnvelop.PutCoords(mapMinx, mapMiny, mapMaxx, mapMaxy);  //这里设置mapframe的大小
           IGeometry pGeometry = pEnvelop;
           pElement.Geometry = pGeometry;
           //这里设置page的大小
           IPage pPage = axPageLayoutControl.Page;
           pPage.Orientation = direction;
           pPage.PutCustomSize(pageWidth, pageHeight);
       }

       
   }
}
